<!doctype html>
<html>

<head>
	<meta charset="UTF-8">
	<title>鼓励金营销</title>
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<link href="__INDEX__/store/css/mui.min.css" rel="stylesheet" />
	<!--App自定义的css-->
	<link rel="stylesheet" type="text/css" href="__INDEX__/store/css/app.css"/>
	<link rel="stylesheet" type="text/css" href="__INDEX__/store/css/style.css"/>
	<link rel="stylesheet" href="__INDEX__/store/css/iconfont.css" />
	<link rel="stylesheet" href="__INDEX__/store/css/wallet.css" />
	<style type="text/css">
		.ypay_jfnr .left{width: 72%;}
		.ypay_jfnr .btn_shez{width: 85%;}
	</style>
</head>

<body>
	<header class="mui-bar mui-bar-nav">
	    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" href="JavaScript:history.go(-1)"></a>
	    <h1 class="mui-title">鼓励金营销</h1>
	</header>
	<div class="mui-content">
	    <div class="ypay_top">
	    	<div class="ypay_tbac"><img src="__INDEX__/store/images/bac_yunpay.jpg"></div>
	    	<div class="ypay_jfye">
	    		<p class="ypay_jfnum">{$agent_info['score']}</p>
	    		<p class="wz">鼓励金</p>
	    	</div>
	    </div>
	    <div class="ypay_jfdk">
	    	<div class="index_sjlisbt clearfix" >
	    		<div style=" width: 70%; float: left; line-height: 30px;">
	    			<i style="background: #D6AA50;"></i>鼓励金营销：&nbsp;&nbsp;
	    			<span class="score_yx" style="color: #FF7831;font-size: 13px;"></span>
	    		</div>
	    		{if $agent_info['is_score'] == 1}
					<div class="is_jfyx mui-switch mui-active" style="float: right;">
						<div class="mui-switch-handle"></div>
					</div> 
				{else}
					<div class="is_jfyx mui-switch " style="float: right;">
						<div class="mui-switch-handle"></div>
					</div> 
	    		{/if}
	    		
	    	</div>
	    	<div class="ypay_jfnr clearfix">	    		
	    		<div class="left" style="width:100%;">
	    			<label>鼓励金抵扣比例：</label>
	    			<input type="text" id="ad_score" value="{$agent_info['ad_score']}" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" /><em>%</em>
	    			<button style="width: 15%; float: right;background: #D6AA50;" type="button" onclick="score_dikou()" class="btn_shez">保存</button>
	    		</div>
	    	</div>
	    	<div class="ypay_jfnr clearfix">	    		
	    		<div class="left" style="width:100%;">
	    			<label>鼓励金赠送比例：</label>
	    			<input type="text" id="give_scale" value="{$agent_info['zs_score']}" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" /><em>%</em>
	    			<button style="width: 15%; float: right;background: #D6AA50;" type="button" onclick="score_give()" class="btn_shez">保存</button>
	    		</div>
	    	</div>
	    </div>
	    {if $Think.config.open_sq==1}
	    	<div class="ypay_ztbox">
		    	<ul class="ypay_ztlist">
		    		<div class="index_sjlisbt clearfix" style="padding: 3% 0;">
			    		<div style=" width: 70%; float: left; line-height: 30px;">
			    			<i></i>共享云商圈&nbsp;&nbsp;
			    			<span class="yun_sq" style="color: #FF7831;font-size: 13px;"></span>
			    		</div>
			    		<div class="yun_area mui-switch" style="float: right;">
							<div class="mui-switch-handle"></div>
						</div>
			    	</div>
		    		<li class="clearfix">
		    			<div class="left">单客次广告费：<span><em id="ad_one">0.00</em>&nbsp;元/次</span></div>
			    		<div class="right"></div>
		    		</li>
		    		<li class="clearfix">
		    			<div class="left">广告佣金：<span><em id='commission'>{$agent_info['commission']}</em>元</span></div>
			    		<div class="right"></div>
		    		</li>
		    		<li class="special clearfix">
		    			<div class="left">广告余额：<span><em id='ad_money'>{$agent_info['ad_money']}</em>元</span></div>
		    			<div ><a id="ads_cz" style="padding:6px;width:80px;background-color: #FF5A00;color:#fff" >广告充值</a></div>
		    		</li>
		    	</ul>
		    </div>
	    {/if}
	</div>
	
</body>
</html>
{include file="public/footer" /}
<script>
	$(function(){
		mui.init({
			swipeBack:true //启用右滑关闭功能
		});
		mui('.cut_store_state .mui-switch').each(function() { //循环所有toggle
			/**
			 * toggle 事件监听
			 */
			this.addEventListener('toggle', function(event) {
				//event.detail.isActive 可直接获取当前状态
				this.parentNode.querySelector('span').innerText = (event.detail.isActive ? '开放店铺' : '单店铺');
				is_round(event.detail.isActive?1:0);
			});
		});
		mui('.is_jfyx').each(function() { //循环所有toggle
			//toggle.classList.contains('mui-active') 可识别该toggle的开关状态
			this.parentNode.querySelector('span').innerText = (this.classList.contains('mui-active') ? '已开启鼓励金营销' : '已关闭鼓励金营销');
			/**
			 * toggle 事件监听
			 */
			this.addEventListener('toggle', function(event) {
				//event.detail.isActive 可直接获取当前状态
				this.parentNode.querySelector('span').innerText = (event.detail.isActive ? '已开启鼓励金营销' : '已关闭鼓励金营销');
				is_score(event.detail.isActive?1:2);
			});
		});
		mui('.yun_area').each(function() { //循环所有toggle
			//toggle.classList.contains('mui-active') 可识别该toggle的开关状态
			this.parentNode.querySelector('span').innerText = (this.classList.contains('mui-active') ? '已开启商圈' : '已关闭商圈');
			/**
			 * toggle 事件监听
			 */
			this.addEventListener('toggle', function(event) {
				//event.detail.isActive 可直接获取当前状态
				this.parentNode.querySelector('span').innerText = (event.detail.isActive ? '已开启商圈' : '已关闭商圈');
				is_ads(event.detail.isActive?2:1);
				if(event.detail.isActive){
					if("{$agent_info['ad_money']}"<100){
						layer.msg('广告余额不足请及时充值', {
						  time: 3000 
						}, function(){
							location.href = 'chongzhi.html?store_id='+"{$agent_info['id']}"+'&fromuid='+"{$agent_info['user_id']}";
						});
					}
				}
			});
		});
		
		
		
		/*//鼓励金充值 
		$('.ypay_jfye').click(function(){
			location.href = 'pay_score.html?store_id='+"{$agent_info['id']}";
		});
		$('#pay_ads').click(function(){
			location.href = 'chongzhi.html?type=pay_ads&store_id='+"{$agent_info['id']}";
		});*/
	})
 		//启用鼓励金管理
	    function is_score(status){
	    	 $.ajax({
	    	 	async: false,
	    	 	url: 'is_score',
				data: {
						state		:status,
						store_id	: "{$agent_info['id']}"
				},
				success: function(data) {
					layer.msg(data.msg, {
						  time: 1000 
						}, function(){
						});
				}
			});
	    }
	    //开启云商圈
	     function is_ads(status){
	    	 $.ajax({
	    	 	async: false,
	    	 	url: 'is_ads',
				data: {
						state		:status,
						store_id	: "{$agent_info['id']}"
				},
				success: function(data) {
					layer.msg(data.msg, {
						  time: 1000 
						}, function(){
						});
				}
			});
	    }
	    //店铺状态
	    function is_round(status){
	    	 $.ajax({
	    	 	async: false,
	    	 	url: 'is_agent_round',
				data: {
						state		:status,
						store_id	: "{$agent_info['id']}"
				},
				success: function(data) {
					layer.msg(data.msg, {
						  time: 1000 
						}, function(){
						});
				}
			});
	    } 
	     
	     
	     
	//鼓励金抵扣比例
    function score_dikou(){
    	layer.confirm('确认修改鼓励金抵扣比例？', 
		{btn: ['确定','取消'],area: ['80%', '170px']}, 
		function(){
			var jifend=document.getElementById('ad_score').value;
			if(isNaN(jifend)){
				layer.msg('请输入合法数字', {icon: 2});
			}else{
				$.ajax({
					url: 'score_dikou',
					data: {
						bili	:$("#ad_score").val(),
						store_id	: "{$agent_info['id']}"
					},
					success: function(data) {
						layer.msg(data.msg, {
						  time: 1000 
						}, function(){
							location.reload();
						});
						 
					}
					
				});
			}
		});
    }
    //鼓励金赠送比例
    function score_give(){
    	layer.confirm('确认修改鼓励金赠送比例？', 
		{btn: ['确定','取消'],area: ['80%', '170px']}, 
		function(){
			var jifend=document.getElementById('give_scale').value;
			if(isNaN(jifend)){
				layer.msg('请输入合法数字', {icon: 2});
			}else{
				$.ajax({
					url: 'score_give',
					data: {
						bili		:$("#give_scale").val(),
						store_id	: "{$agent_info['id']}"
					},
					success: function(data) {
						layer.msg(data.msg, {
						  time: 1000 
						}, function(){
							location.reload();
						});
						 
					}
					
				});
			}
		});
    }
    //单次广告费
    function ads_money(){
    	layer.confirm('确定修改单客次广告费？', 
			{btn: ['确定','取消'], area: ['80%', '170px']}, 
			function(){
				if(isNaN($("#ad_one").val())){
					layer.msg('请输入合法金额', {icon: 2});
				}else{
					$.ajax({
						url: 'ads_money',
						data: {
							ads_money	:$("#ad_one").val(),
							store_id	: "{$agent_info['id']}"
						},
						success: function(data) {
							 layer.msg(data.msg, {
							  time: 1000 
							}, function(){
								location.reload();
							});
						}
					});
				}
		});
   }
	
</script>